package com.colin.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.colin.mapper.RightsMapper;
import com.colin.pojo.Rights;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author :Colin
 * @version 创建时间: 2021/8/12 20:31
 */
@Service
public class RightsSeriveImpl implements RightsService {
    @Autowired
    private RightsMapper rightsMapper;
    @Override
    public List<Rights> getList() {
        QueryWrapper<Rights> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent_id", 0);
        List<Rights> oneList = rightsMapper.selectList(queryWrapper);
        for(Rights oneRightsItem:oneList){
            queryWrapper.clear();
            queryWrapper.eq("parent_id", oneRightsItem.getId());
            List<Rights> twoList = rightsMapper.selectList(queryWrapper);
            oneRightsItem.setChildren(twoList);
        }

        return oneList;
    }
}
